<template>
  <div class="taps" v-loading="loading">
    <div class="line"></div>
    <div class="border"></div>
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane v-for="item, index in tapList" :key="index" :label="item[tapProps.label]"
        :name="item[tapProps.name]">
        <slot />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
export default {
  name: 'TapList',
  props: {
    setBtnIndex: {
      type: Number,
      default: () => {
        return 0
      }
    },
    tapList: {
      type: Array,
      default: () => {
        return []
      }
    },
    tapProps: {
      type: Object,
      default: () => {
        return {
          label: 'label',
          name: 'name'
        }
      }
    }
  },
  data() {
    return {
      loading: false,
      activeName: ''
    };
  },
  watch: {
    tapList(v) {
      this.activeName = v.length ? v[0][this.tapProps.name] : ''
      this.handleClick();
    }
  },
  mounted() {
  },
  methods: {
    handleClick() {
      let rut = this.tapList.find(e => e[this.tapProps.name] == this.activeName);
      this.$emit('handleClickTabs', rut);
    },
  }
};
</script>

<style lang="scss" scoped>
.taps {
  width: 100%;
  height: 100%;
  position: relative;

  .line {
    position: absolute;
    width: 100%;
    border-top: 1px solid #CCD4F5;
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
  }

  .border {
    width: 100%;
    height: calc(100% - 22px);
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
    border: 1px solid #CCD4F5;
    position: absolute;
  }

  ::v-deep .el-tabs {
    width: 100%;
    height: 100%;
  }

  ::v-deep .el-tabs .el-tabs__content {
    width: 100%;
    height: calc(100% - 40px);

    .el-tab-pane {
      width: 100%;
      height: 100%;
    }
  }

  ::v-deep .el-tabs--border-card {
    border: none;
    box-shadow: none;
    background-color: transparent;

    .el-tabs__header {
      margin: 0 15px;
      border: none;
      background-color: transparent;
    }
  }

  ::v-deep .el-tabs__nav {
    .el-tabs__item {
      margin: 0 15px;
      margin-left: 0px;
      border-radius: 3px;
      background: #ffffff;
      border: 1px solid #CCD4F5 !important;
      font-size: 18px !important;

      &:after {
        content: '';
        position: absolute;
        width: 100%;
        height: 22px;
        left: 0;
        border: 1px solid #ccd4f500;
      }
    }

    .is-active {
      border: 1px solid #ccd4f500 !important;
      background: #F8F8F8 !important;
      border-radius: 3px !important;
      color: #6176D0 !important;

      &:hover {
        color: #6176D0 !important;
      }

      &:after {
        content: '';
        position: absolute;
        width: calc(100% + 2px);
        height: 21px;
        left: -1px;
        border: 1px solid #CCD4F5;
        border-radius: 3px 3px 0 0;
        border-bottom: none;
      }

    }
  }

  ::v-deep .el-tabs__nav-prev,
  ::v-deep .el-tabs__nav-next {
    background: #F8F8F8;
    border: 1px solid #CCD4F5;
    height: 40px;
  }
}
</style>